package com.medmarkmobile.gui;

import com.example.medmarkmobile.R;
import com.medmarkmobile.connection.ConexaoLogin;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;

public class Login extends Activity{
	
	private Button botaoCadastrar, botaoLogin;
	private EditText loginEditText, senhaEditText;
	private Boolean loginResult = false;
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
	    getActionBar().hide();
		
		setContentView(R.layout.activity_login);
		
		loginEditText = (EditText) findViewById(R.id.mainLoginEditText);
		senhaEditText = (EditText) findViewById(R.id.mainSenhaEditText);
		
		
		botaoCadastrar = (Button) findViewById(R.id.botaoCadastrarMain);
		final Intent i = new Intent(this, TelaCadastro.class);
		
		botaoLogin = (Button) findViewById(R.id.botaoLoginMain);
		
		botaoLogin.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				String[] params = new String[2];
				params[0] = loginEditText.getText().toString();
				params[1] = senhaEditText.getText().toString();
				
				loginEditText.setText("");
				senhaEditText.setText("");
				
				new ConexaoLogin(Login.this).execute(params);
				
			}
		});
		
		botaoCadastrar.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				startActivity(i);
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {

		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		return super.onOptionsItemSelected(item);
	}
	
	public void setLoginResult(Boolean result){
		this.loginResult = result;
	}
	
	public void prinLoginResult(){
		System.out.println(loginResult);
	}


}
